home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / ace23.lha / MAIN.lha / include / julian.h < prev    next >
Text File  |  1994-10-22  |  2KB  |  83 lines

  1. { Julian Date calculations. 
  2.  
  3.   These routines were taken from Peter Duffett-Smith's 
  4.   "Astronomy with your Personal Computer". 
  5.  
  6.   Conversion from line-numbered BASIC to C to ACE-BASIC 
  7.   by David Benn, 2nd,8th,9th April 1993. } 
  8.   
  9. SUB julday(caldate$) 
  10.  
  11. single m1,y1,a,b,c,d,dj
  12.  
  13. { This routine calculates the number of days elapsed 
  14.   since the epoch 1900 January 0.5 (ie: 1200 GMT, 31st Dec 1899). } 
  15.  
  16.  '..convert date string (mm-dd-yyyy) into dy,mn,yr
  17.  dy=val(mid$(caldate$,4,2))
  18.  mn=val(mid$(caldate$,1,2))
  19.  yr=val(right$(caldate$,4))
  20.  
  21.  if yr = 0 then 
  22.    dj=-1  '..error 
  23.  else 
  24.    m1=mn : y1=yr : b=0 
  25.  
  26.   if y1 < 1 then ++y1 
  27.   if mn < 3 then m1=mn+12 : --y1 
  28.  
  29.   if y1 > 1582 or mn > 10 or dy >= 15 then  
  30.     a=int(y1/100) : b=2-a+int(a/4) 
  31.     c=int(365.25*y1)-694025 
  32.     if y1 < 0 then c=fix((365.25*y1)-0.75)-694025 
  33.     d=int(30.6001*(m1+1))
  34.     dj=b+c+d+dy-0.5 
  35.   else 
  36.     if (y1<1582 or (y1=1582 and mn<10) or (y1=1582 and mn=10 and dy<5)) then
  37.       c=int(365.25*y1)-694025 
  38.       if y1 < 0 then c=fix((365.25*y1)-0.75)-694025 
  39.       d=int(30.6001*(m1+1)); dj=b+c+d+dy-0.5 
  40.     else 
  41.       dj=-1  '..error
  42.     end if
  43.   end if 
  44.  end if
  45.  
  46.  julday = dj  '..Return Julian Date (error = -1)
  47. END SUB
  48.  
  49. SUB calday$(dj!) 
  50.  
  51. single a,b,c,d,g,i,fd
  52.  
  53. { This routine converts the number of (Julian) days since 
  54.   1900 January 0.5 into the calendar date. }
  55.  
  56.  d=dj!+0.5 : i=int(d) : fd=d-i 
  57.  
  58.  if fd = 1 then fd=0 : ++i 
  59.  
  60.  if i > -115860 then 
  61.    a=int((i/36524.25)+9.9835726e-1)+14 
  62.    i=i+1+a-int(a/4) 
  63.  end if 
  64.  
  65.  b=int((i/365.25)+8.02601e-1) 
  66.  c=i-int((365.25*b)+7.50001e-1)+416 
  67.  g=int(c/30.6001) : mn=g-1 
  68.  dy=c-int(30.6001*g)+fd : yr=b+1899 
  69.  if g > 13.5 then mn=g-13 
  70.  if mn < 2.5 then yr=b+1900 
  71.  if yr < 1 then --yr 
  72.  
  73.  '..return a date string (whole days only) 
  74.  dy$=str$(int(dy)) : if dy < 10 then dy$="0"+right$(dy$,1)
  75.  dy$=right$(dy$,2)
  76.  mn$=str$(int(mn)) : if mn < 10 then mn$="0"+right$(mn$,1)
  77.  mn$=right$(mn$,2)
  78.  yr$=str$(int(yr))
  79.  yr$=right$(yr$,4)
  80.  
  81.  calday$ = mn$+"-"+dy$+"-"+yr$
  82. END SUB 
  83.